/*
 * The Open Source Unix Installer
 *
 * The MIT License
 *
 * Copyright 2011-2012 Andrey Pudov.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/*
 * @author  Andrey Pudov    <andrey@andreypudov.com>
 * @version 0.00.00
 * @name    u_xml_attribute.h
 * @date:   Feb 26, 2012
 */

#ifndef INSTALLER_UTIL_XML_U_ATTRIBUTE_H_
#define INSTALLER_UTIL_XML_U_ATTRIBUTE_H_

#include <stdio.h>
#include <stdbool.h>

#include "xml_attribute.h"

#include "u_main.h"

#ifdef __cplusplus
extern "C" {
#endif

bool u_installer_xml_attribute_start();          /* unit entry point */

bool u_installer_xml_attribute_new();
bool u_installer_xml_attribute_delete();
bool u_installer_xml_attribute_get_name();
bool u_installer_xml_attribute_get_value();
bool u_installer_xml_attribute_set_name();
bool u_installer_xml_attribute_set_value();

bool u_installer_xml_attribute_start() {
    return (u_installer_xml_attribute_new()
        && u_installer_xml_attribute_delete()
        && u_installer_xml_attribute_get_name()
        && u_installer_xml_attribute_get_value()
        && u_installer_xml_attribute_set_name()
        && u_installer_xml_attribute_set_value());
}

bool u_installer_xml_attribute_new() {
    XMLAttribute *attribute = installer_xml_attribute_new(L"attr1", L"val1");

    if (attribute == NULL) {
        u_installer_main_print("xml_attribute", "new()", false);

        return false;
    }
    
    u_installer_main_print("xml_attribute", "new()", true);

    installer_xml_attribute_delete(attribute);

    return true;
}

bool u_installer_xml_attribute_delete() {
    /* unit case is a part of new() */        
    u_installer_main_print("xml_attribute", "delete()", true);

    return true;
}

bool u_installer_xml_attribute_get_name() {
    XMLAttribute *attribute = installer_xml_attribute_new(L"attr1", L"val1");

    if (attribute == NULL) {
        u_installer_main_print("xml_attribute", "get_name()", false);

        return false;
    }

    if (wcscmp(installer_xml_attribute_get_name(attribute), L"attr1") != 0) {
        u_installer_main_print("xml_attribute", "get_name()", false);
    
        return false;
    }
    
    u_installer_main_print("xml_attribute", "get_name()", true);

    installer_xml_attribute_delete(attribute);

    return true;
}

bool u_installer_xml_attribute_get_value() {
    XMLAttribute *attribute = installer_xml_attribute_new(L"attr1", L"val1");

    if (attribute == NULL) {
        u_installer_main_print("xml_attribute", "get_value()", false);

        return false;
    }

    if (wcscmp(installer_xml_attribute_get_value(attribute), L"val1") != 0) {
        u_installer_main_print("xml_attribute", "get_value()", false);

        return false;
    }
    
    u_installer_main_print("xml_attribute", "get_value()", true);

    installer_xml_attribute_delete(attribute);

    return true;
}

bool u_installer_xml_attribute_set_name() {
    XMLAttribute *attribute = installer_xml_attribute_new(L"attr1", L"val1");

    if (attribute == NULL) {
        u_installer_main_print("xml_attribute", "set_name()", false);

        return false;
    }

    installer_xml_attribute_set_name(attribute, L"attr2");

    if (wcscmp(installer_xml_attribute_get_name(attribute), L"attr2") != 0) {
        u_installer_main_print("xml_attribute", "set_name()", false);

        return false;
    }
    
    u_installer_main_print("xml_attribute", "set_name()", true);

    installer_xml_attribute_delete(attribute);

    return true;
}

bool u_installer_xml_attribute_set_value() {
    XMLAttribute *attribute = installer_xml_attribute_new(L"attr1", L"val1");

    if (attribute == NULL) {
        u_installer_main_print("xml_attribute", "set_value()", false);

        return false;
    }

    installer_xml_attribute_set_value(attribute, L"val2");

    if (wcscmp(installer_xml_attribute_get_value(attribute), L"val2") != 0) {
        u_installer_main_print("xml_attribute", "set_value()", false);

        return false;
    }
    
    u_installer_main_print("xml_attribute", "set_value()", true);

    installer_xml_attribute_delete(attribute);

    return true;
}

#ifdef __cplusplus
}
#endif

#endif /* INSTALLER_UTIL_XML_U_ATTRIBUTE_H_ */ 
